<template>
    <div class="chart-container">
        <div class="chart-title">
            <p class="p1">组网分布</p>
            <p class="p2">圆形面积代表符号速率,信噪比0.5s实为信噪比不明</p>
        </div>
        <div ref="chartRef" style="width: 100%; height: 500px"></div>
    </div>
</template>
<script lang="ts">
import { defineComponent, ref, Ref, onMounted } from 'vue';
import { useECharts } from '/@/hooks/web/useECharts';

export default defineComponent({
  setup() {
    
    const chartRef = ref<HTMLDivElement | null>(null);
    const { setOptions, resize, echarts, getInstance } = useECharts(
      chartRef as Ref<HTMLDivElement>,
    );

    const data = [
      [
        [3612.5, 12, 17096869, 1990],
        [3700, 19.4, 27662440, 1990],
        [3800, 8, 1154605773, 1990],
        [3900, 4.7, 10582082, 1990],
        [4000, 7, 4986705, 1990],
        [4100, 5.4, 252847810, 1990]
      ],
      [
        [4200, 20.5, 126573481, 'Japan', 2015],
        [4300, 11.4, 64715810, 'United Kingdom', 2015],
        // [53354, 14.1, 321773631, 'United States', 2015]
      ],
      [
        [4400, 20, 23968973, 'Australia', 2016],
        [4500, 10, 35939927, 'Canada', 2016],
        [4600, 15.5, 11389562, 'Cuba', 2016],
      ]
    ];
    function do_get_chars() {
      setOptions({
        // backgroundColor: new echarts.graphic.RadialGradient(0.3, 0.3, 0.8, [
        //   {
        //     offset: 0,
        //     color: '#f7f8fa'
        //   },
        //   {
        //     offset: 1,
        //     color: '#cdd0d5'
        //   }
        // ]),
        // title: {
        //   text: 'Life Expectancy and GDP by Country',
        //   left: '5%',
        //   top: '3%'
        // },
        legend: {
          left: 'center',
          //   right: '10%',
          top: '4%',
          data: ['VSAT组网2', 'VSAT组网1', 'VSAT组网4']
        },
        grid: {
          left: '8%',
          top: '25%'
        },
        xAxis: {
          splitLine: {
            lineStyle: {
              type: 'dashed'
            }
          }
        },
        yAxis: {
          splitLine: {
            lineStyle: {
              type: 'dashed'
            }
          },
          scale: true
        },
        series: [
          {
            name: 'VSAT组网2',
            data: data[0],
            type: 'scatter',
            symbolSize: function (data) {
              return Math.sqrt(data[2]) / 5e2;
            },
            emphasis: {
              focus: 'series',
              label: {
                show: true,
                formatter: function (param) {
                  return param.data[1];
                },
                position: 'top'
              }
            },
            itemStyle: {
              shadowBlur: 10,
              shadowColor: 'rgba(120, 36, 50, 0.5)',
              shadowOffsetY: 5,
              color: '#B34038'
            }
          },
          {
            name: 'VSAT组网1',
            data: data[1],
            type: 'scatter',
            symbolSize: function (data) {
              return Math.sqrt(data[2]) / 5e2;
            },
            emphasis: {
              focus: 'series',
              label: {
                show: true,
                formatter: function (param) {
                  return param.data[1];
                },
                position: 'top'
              }
            },
            itemStyle: {
              shadowBlur: 10,
              shadowColor: 'rgba(25, 100, 150, 0.5)',
              shadowOffsetY: 5,
              color: '#344453'
            }
          },
          {
            name: 'VSAT组网4',
            data: data[2],
            type: 'scatter',
            symbolSize: function (data) {
              return Math.sqrt(data[2]) / 5e2;
            },
            emphasis: {
              focus: 'series',
              label: {
                show: true,
                formatter: function (param) {
                  return param.data[1];
                },
                position: 'top'
              }
            },
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetY: 5,
              color: '#709EA6'
            }
          }
        ],
        dataZoom: [
          {
            type: 'slider', // 外部slider  
            start: 10, // 初始时，显示10%到100%的数据  
            end: 100
          },
          {
            type: 'inside', // 内置的缩放区域  
            start: 10,
            end: 100
          }
        ],
        toolbox: {
            right:"5%",
            top:"20px",
            feature: {
              dataView:{},
              restore: {},
              saveAsImage: {},
            },
          },
      });

    }
    onMounted(() => {
      do_get_chars()
    })
    return {
      chartRef,
      do_get_chars
    }
  }
})

</script>
<style lang=less scoped>
.chart-container {
    position: relative;

    .chart-title {
        position: absolute;
        top: 20px;
        z-index: 2;
        left: 40px;

        p {
            margin-bottom: 0;
        }

        .p1 {
            font-size: 20px;
            font-weight: bold;
        }

        .p2 {
            color: #999;
        }
    }
}
</style>